﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Acceron.University.DBAccess;

namespace GA_Scheduler
{
    public class Configuration
    {
        private static Configuration singleton;
        private int numberOfClasses = -1;
        private int numberOfRooms = -1;
        private Random rnd;
        
        private Room[] rooms;
        private Group[] groups;
        private Class[] classes;
        private Professor[] professors;
        private GaContext context;

        private Configuration()
        {
            context = new GaContext();
        }

        public GaContext Context
        {
            get { return context; }
        }

        public Room[] Rooms
        {
            get
            {
                if (rooms == null)
                {
                    rooms = context.Rooms.ToArray();
                }

                return rooms;
            }
        }

        public Group[] Groups
        {
            get
            {
                if (groups == null)
                {
                    groups = context.Groups.ToArray();
                }

                return groups;
            }
        }

        public Professor[] Professors
        {
            get
            {
                if (professors == null)
                {
                    professors = context.Professors.ToArray();
                }
                return professors;
            }
        }

        public Class[] Classes
        {
            get
            {
                if (classes == null)
                {
                    classes = context.Classes.ToArray();
                }

                return classes;
            }
        }

        public static Configuration Instance
        {
            get 
            {
                if (singleton == null)
                    singleton = new Configuration();

                return singleton;
            }
        }

        public int NumberOfClasses
        {
            get
            {
                if (numberOfClasses == -1)
                {
                    numberOfClasses = Classes.Count();
                }

                return numberOfClasses;
            }
        }

        public void RefreshRandom()
        {
            rnd = new Random();
        }
       
        public Random Rand
        {
            get
            {
                if(rnd == null)
                {
                    rnd = new Random();
                }
                return rnd;
            }
        }

        public int NumberOfRooms
        {
            get
            {
                if (numberOfRooms == -1)
                {
                    numberOfRooms = Rooms.Count();
                }

                return numberOfRooms;
            }
        }

    }
}
